<template>
  <div class="canvas-wrapper">
    <canvas id="canvas" class="canvas" width="499" height="598"></canvas>
    <div class="bgColor"></div>
    <div class="text">
      <h1 class="h1">程序员的世界</h1>
      <h2 class="h2">只剩下撸猫和键盘还有...</h2>
      <h2 class="h2 yellow">动漫</h2>
      <div class="resume mt">
        <div v-for="i in textData" :key="i.id" class="li">{{ i }}</div>
        <br>
        <hr>
        <br>
        <div>
          <nuxt-link class="theme" to="/">知否</nuxt-link>：专注于程序员写博客,聊天室,音乐的网站
        </div>
        <br>
        <small>梦想需要努力,而努力需要方式</small>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'

export default Vue.extend({
  data() {
    return {
      sun: require('static/4.png'),
      textData: [
        '成年人的世界很苦',
        '程序员也不例外',
        '但是梦想总是要有的',
        '万一实现了呢!'
      ]
    }
  },
  mounted() {
    var sun = new Image()
    var moon = new Image()
    var earth = new Image()
    const init = () => {
      sun.src = this.sun
      moon.src = 'https://mdn.mozillademos.org/files/1443/Canvas_moon.png'
      earth.src = 'https://mdn.mozillademos.org/files/1429/Canvas_earth.png'
      window.requestAnimationFrame(draw)
    }

    function draw() {
      const dom: any = document.getElementById('canvas')
      var ctx = dom.getContext('2d')
      ctx.globalCompositeOperation = 'destination-over'
      ctx.clearRect(0, 0, 479, 558) // clear canvas
      ctx.fillStyle = 'rgba(0,0,0,0.4)'
      ctx.strokeStyle = 'rgba(0,153,255,0.4)'
      ctx.save()
      ctx.translate(20, 20)
      // Earth
      var time = new Date()
      ctx.rotate(
        ((2 * Math.PI) / 60) * time.getSeconds() +
          ((2 * Math.PI) / 60000) * time.getMilliseconds()
      )
      ctx.translate(105, 0)
      ctx.drawImage(earth, -12, -12)
      ctx.save()
      ctx.rotate(
        ((2 * Math.PI) / 6) * time.getSeconds() +
          ((2 * Math.PI) / 6000) * time.getMilliseconds()
      )
      ctx.translate(0, 28.5)
      ctx.drawImage(moon, -3.5, -3.5)
      ctx.restore()
      ctx.restore()
      ctx.beginPath()
      ctx.arc(20, 20, 105, 0, Math.PI * 2, false)
      ctx.stroke()
      ctx.drawImage(sun, -10, -10, 185, 185)
      window.requestAnimationFrame(draw)
    }

    init()
  }
})
</script>

<style scoped lang="scss">
.canvas-wrapper {
  width: 100%;
  height: 100%;
  position: relative;
}
.bgColor {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  &:before {
    // background-image: url('static/login-left-bottom.png');
    background-image: url("static/canvas-left.png");
    background-repeat: no-repeat;
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
  }
  &:after {
    background-image: url("static/canvas-right.png");
    background-repeat: no-repeat;
    background-position: right bottom, left top;
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
  }
  background: linear-gradient(0deg, #3a485a 0%, #607089 100%);
}
.text {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  padding: 60px;
  text-align: right;
  color: #eee;
  .h1 {
    width: 100%;
    height: 60px;
    line-height: 60px;
  }
  .h2 {
    width: 100%;
    height: 40px;
    line-height: 40px;
  }
  .yellow {
    color: yellow;
  }
  .resume {
    width: 100%;
    .li {
      line-height: 30px;
    }
    .theme {
      color: var(--tmColor);
      text-decoration: underline;
    }
  }
}
#canvas {
  position: absolute;
  z-index: 99;
}
</style>
